//
//  CollectionDetailCellModel.m
//  Tang
//
//  Created by 邓芮 on 15/12/7.
//  Copyright © 2015年 352324497@qq.com. All rights reserved.
//

#import "CollectionDetailCellModel.h"

@implementation CollectionDetailCellModel
- (void)setValue:(id)value forUndefinedKey:(NSString *)key
{
    if ([key isEqualToString:@"id"])
    {
        [self setValue:value forKey:@"Id"];
    }
}

+ (NSMutableArray *)JsonWithDic:(NSDictionary *)dic modelArray:(NSMutableArray *)modelArray
{
    NSDictionary *dataDic = dic[@"data"];
    NSArray *array = dataDic[@"list"];
    for (NSDictionary *listDic in array)
    {
        CollectionDetailCellModel *model = [[CollectionDetailCellModel alloc]init];
        [model setValuesForKeysWithDictionary:listDic];
        
        NSDictionary *dyDic = listDic[@"dynamic"];
        model.comments = dyDic[@"comments"];
        model.likes = dyDic[@"likes"];
        
        model.authorDic = [NSMutableDictionary dictionary];
        UserModel *userModel = [[UserModel alloc]init];
        [userModel setValuesForKeysWithDictionary:listDic[@"author"]];
        [model.authorDic setValue:userModel forKey:@"authorInfo"];
        NSMutableArray *picArr = listDic[@"pics"];
        model.picArray = [NSMutableArray array];
        for (NSDictionary *picDic in picArr)
        {
            PictureModel *picModel = [[PictureModel alloc]init];
            [picModel setValuesForKeysWithDictionary:picDic];
            [model.picArray addObject:picModel];
        }
        model.productArray = [NSMutableArray array];
        for (NSDictionary *productDic in listDic[@"product"])
        {
            ProductModel *proModel = [[ProductModel alloc]init];
            [proModel setValuesForKeysWithDictionary:productDic];
            [model.productArray addObject:proModel];
        }
        
        model.tagsArray = [NSMutableArray array];
        for (NSDictionary *tagDic in listDic[@"tags"])
        {
            TagModel *tagModel = [[TagModel alloc]init];
            [tagModel setValuesForKeysWithDictionary:tagDic];
            [model.tagsArray addObject:tagModel];
        }
        [modelArray addObject:model];
    
    }
    return modelArray;
}

+ (CollectionDetailCellModel *)JsonWithDetailDic:(NSDictionary *)dic
{
    NSDictionary *dataDic = dic[@"data"];
    NSDictionary *postDic = dataDic[@"post"];
    CollectionDetailCellModel *model = [[CollectionDetailCellModel alloc]init];
    [model setValuesForKeysWithDictionary:postDic];
    model.authorDic = [NSMutableDictionary dictionary];
    NSDictionary *authorDic = postDic[@"author"];
    UserModel *userModel = [[UserModel alloc]init];
    [userModel setValuesForKeysWithDictionary:authorDic];
    [model.authorDic setValue:userModel forKey:@"authorInfo"];
    NSMutableArray *picArr = postDic[@"pics"];
    model.picArray = [NSMutableArray array];
    for (NSDictionary *picDic in picArr)
    {
        PictureModel *picModel = [[PictureModel alloc]init];
        [picModel setValuesForKeysWithDictionary:picDic];
        [model.picArray addObject:picModel];
    }

    model.productArray = [NSMutableArray array];
    for (NSDictionary *productDic in postDic[@"product"])
    {
        ProductModel *proModel = [[ProductModel alloc]init];
        [proModel setValuesForKeysWithDictionary:productDic];
        [model.productArray addObject:proModel];
    }
    
    NSDictionary *dyDic = postDic[@"dynamic"];
    model.comments = dyDic[@"comments"];
    model.likes = dyDic[@"likes"];
    
    model.tagsArray = [NSMutableArray array];
    for (NSDictionary *tagDic in postDic[@"tags"])
    {
        TagModel *tagModel = [[TagModel alloc]init];
        [tagModel setValuesForKeysWithDictionary:tagDic];
        [model.tagsArray addObject:tagModel];
    }
    
    return model;

}
@end
